package service.impl;

import core.Page;
import dao.StudentDao;
import domain.Student;
import service.StudentService;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 于金鹏
 * @Date 2024/12/16 16:25
 * @Package StudentCheckSystem
 */
public class StudentServiceImpl implements StudentService {

    private final StudentDao studentDao;

    public StudentServiceImpl(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    @Override
    public List<Student> getAllStudents(Student student) throws SQLException {
        return studentDao.getAllStudents(student);
    }

    @Override
    public int addStudent(Student student) throws SQLException {
        return this.studentDao.addStudent(student);
    }

    @Override
    public int deleteStudent(int id) throws SQLException {
        return this.studentDao.deleteStudent(id);
    }


    @Override
    public int updateStudent(Student student) throws SQLException {
        return this.studentDao.updateStudent(student);
    }

    @Override
    public Student getStudentById(int id) throws SQLException {
        return this.studentDao.getStudentById(id);
    }

    @Override
    public Page<Student> getStudentPage(int pageNum, int pageSize, Student student) throws SQLException {
        int total = this.studentDao.count(student);
        List<Student> records = this.studentDao.page(student,pageNum, pageSize);
        return new Page<>(total,records);
    }

}
